<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>演练脚本保存API测试</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            text-align: center;
        }
        .content {
            padding: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #333;
        }
        input, textarea, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            box-sizing: border-box;
        }
        textarea {
            min-height: 100px;
            resize: vertical;
        }
        .json-input {
            font-family: 'Courier New', monospace;
            background-color: #f8f9fa;
        }
        .btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 12px 24px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            margin-right: 10px;
            transition: transform 0.2s;
        }
        .btn:hover {
            transform: translateY(-2px);
        }
        .btn-secondary {
            background: #6c757d;
        }
        .btn-success {
            background: #28a745;
        }
        .btn-danger {
            background: #dc3545;
        }
        .response {
            margin-top: 20px;
            padding: 15px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            white-space: pre-wrap;
            max-height: 400px;
            overflow-y: auto;
        }
        .response.success {
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            color: #155724;
        }
        .response.error {
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            color: #721c24;
        }
        .response.info {
            background-color: #d1ecf1;
            border: 1px solid #bee5eb;
            color: #0c5460;
        }
        .tabs {
            display: flex;
            border-bottom: 1px solid #ddd;
            margin-bottom: 20px;
        }
        .tab {
            padding: 10px 20px;
            cursor: pointer;
            border: none;
            background: none;
            border-bottom: 2px solid transparent;
        }
        .tab.active {
            border-bottom-color: #667eea;
            color: #667eea;
            font-weight: bold;
        }
        .tab-content {
            display: none;
        }
        .tab-content.active {
            display: block;
        }
        .status {
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 15px;
            font-weight: bold;
        }
        .status.success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .status.error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .status.info {
            background-color: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }
        .example-data {
            background-color: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 4px;
            padding: 15px;
            margin-bottom: 20px;
        }
        .example-data h4 {
            margin-top: 0;
            color: #495057;
        }
        .example-data pre {
            margin: 0;
            white-space: pre-wrap;
            font-size: 12px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>演练脚本保存API测试</h1>
            <p>测试演练脚本保存功能的完整流程</p>
        </div>
        
        <div class="content">
            <div class="tabs">
                <button class="tab active" onclick="showTab('save')">演练脚本</button>
                <button class="tab" onclick="showTab('drill')">应急预案</button>
                <button class="tab" onclick="showTab('workflow')">全流程测试</button>
                <button class="tab" onclick="showTab('error')">错误测试</button>
            </div>
            
            <!-- 演练脚本测试 -->
            <div id="save" class="tab-content active">
                <h3>演练脚本测试功能</h3>
                <p>测试演练脚本生成和保存功能</p>
                
                <div class="example-data">
                    <h4>演练脚本生成示例数据</h4>
                    <pre id="scriptGenerateExampleData">{
  "equipment": "网络防火墙",
  "sceneDesc": "模拟网络攻击场景，测试应急响应流程",
  "plan": {
    "安全事件监测": "采用实时网络流量分析工具和入侵检测系统(IDS)进行监测。",
    "安全事件分析、定级、上报": "分析流程包括确认事件性质、影响范围和攻击手法；定级依据《通信网络安全事件分级分类指南》。",
    "应急响应处置": "立即隔离受影响系统，防止勒索软件扩散；启动备份恢复流程，确保业务连续性；通知网络安全团队进行技术处置，同时联系法律顾问处理可能的合规和法律问题。",
    "安全事件取证和溯源": "使用数字取证工具收集和分析受感染系统的日志、内存转储和文件样本；通过IP追踪、恶意代码分析和网络行为分析技术溯源攻击者；",
    "安全事件总结、结束响应": "编写详细的事件总结报告，包括事件原因、处置过程、损失评估和改进措施；组织内部评审会议，分享经验教训。"
  },
  "scriptNode": [
    {
      "nodeOrder": 1,
      "nodeName": "演练启动",
      "nodeType": "流程节点",
      "children": [
        {
          "id": "b522fe23-93dc-4b5f-9145-e8c1550ca8c8",
          "nodeName": "默认节点",
          "nodeType": "对话节点",
          "nodeContent": "",
          "participants": {
            "id": "1",
            "name": "安全管理员",
            "groupId": "1f443624-82d1-4ede-9489-d3c5602297f7",
            "groupName": "演练主持人"
          }
        },
        {
          "id": "a08b1a02-7607-46db-9dc9-c401545acb42",
          "nodeName": "默认节点",
          "nodeType": "操作节点",
          "nodeContent": "",
          "participants": {
            "id": "1942491371028934658",
            "name": "二级AA",
            "groupId": "aaa94541-ddc4-4bbc-9ecb-3320bc9ab41e",
            "groupName": "应急响应领导决策组"
          }
        }
      ]
    }
  ]
}</pre>
                </div>
                

                
                <div class="example-data">
                    <h4>演练脚本保存示例数据</h4>
                    <pre id="exampleData">{
  "equipment": "网络防火墙",
  "sceneDesc": "模拟网络攻击场景，测试应急响应流程",
  "plan": {
    "安全事件监测": "采用实时网络流量分析工具和入侵检测系统(IDS)进行监测。",
    "安全事件分析、定级、上报": "分析流程包括确认事件性质、影响范围和攻击手法；定级依据《通信网络安全事件分级分类指南》。",
    "应急响应处置": "立即隔离受影响系统，防止勒索软件扩散；启动备份恢复流程，确保业务连续性。",
    "安全事件取证和溯源": "使用数字取证工具收集和分析受感染系统的日志、内存转储和文件样本。",
    "安全事件总结、结束响应": "编写详细的事件总结报告，包括事件原因、处置过程、损失评估和改进措施。"
  },
  "scriptNode": [
    {
      "nodeOrder": 1,
      "nodeName": "演练启动",
      "nodeType": "流程节点",
      "children": [
        {
          "id": "b522fe23-93dc-4b5f-9145-e8c1550ca8c8",
          "nodeName": "对话节点",
          "nodeType": "对话节点",
          "nodeContent": "演练主持人：各位同事，现在开始进行网络安全事件应急演练。本次演练模拟网络攻击场景，请大家按照预案要求执行相应操作。",
          "participants": {
            "id": "1",
            "name": "安全管理员",
            "groupId": "1f443624-82d1-4ede-9489-d3c5602297f7",
            "groupName": "演练主持人"
          }
        },
        {
          "id": "a08b1a02-7607-46db-9dc9-c401545acb42",
          "nodeName": "操作节点",
          "nodeType": "操作节点",
          "nodeContent": "1. 启动网络监控系统\n2. 检查防火墙状态\n3. 确认应急响应团队就位\n4. 准备应急响应工具",
          "participants": {
            "id": "1942491371028934658",
            "name": "二级AA",
            "groupId": "aaa94541-ddc4-4bbc-9ecb-3320bc9ab41e",
            "groupName": "应急响应领导决策组"
          }
        }
      ]
    }
  ]
}</pre>
                </div>
                
                <div class="form-group">
                    <label for="scriptGenerateUrl">演练脚本生成API地址:</label>
                    <input type="text" id="scriptGenerateUrl" value="http://1.94.252.115:8085/api/v1/generate_drill_script" readonly>
                </div>
                

                
                <div class="form-group">
                    <label for="saveUrl">演练脚本保存API地址:</label>
                    <input type="text" id="saveUrl" value="http://1.94.252.115:8085/api/v1/save_script" readonly>
                </div>
                
                <div class="form-group">
                    <label for="scriptGenerateData">演练脚本生成请求数据 (JSON):</label>
                    <textarea id="scriptGenerateData" class="json-input" placeholder="请输入JSON格式的演练脚本生成请求数据..."></textarea>
                </div>
                

                
                <div class="form-group">
                    <label for="saveData">演练脚本保存请求数据 (JSON):</label>
                    <textarea id="saveData" class="json-input" placeholder="请输入JSON格式的演练脚本保存请求数据..."></textarea>
                </div>
                
                <button class="btn btn-success" onclick="loadScriptGenerateExampleData()">加载演练脚本生成示例数据</button>

                <button class="btn btn-success" onclick="loadExampleData()">加载演练脚本保存示例数据</button>
                <button class="btn" onclick="testScriptGenerate()">测试演练脚本生成</button>

                <button class="btn" onclick="testScriptSave()">测试演练脚本保存</button>
                <button class="btn btn-secondary" onclick="clearResponse('saveResponse')">清空响应</button>
                
                <div id="saveResponse" class="response info">等待测试...</div>
            </div>
            
            <!-- 应急预案测试 -->
            <div id="drill" class="tab-content">
                <h3>应急预案测试功能</h3>
                <p>测试应急预案生成、优化和保存功能</p>
                
                <div class="example-data">
                    <h4>预案生成示例数据</h4>
                    <pre id="drillExampleData">{
  "event_type": "网络安全事件",
  "event_subtype": "数据勒索事件",
  "optimize_field": "",
  "optimize_suggest": "",
  "history": []
}</pre>
                </div>
                
                <div class="example-data">
                    <h4>预案优化示例数据</h4>
                    <pre id="optimizeExampleData">{
  "event_type": "网络安全事件",
  "event_subtype": "数据勒索事件",
  "optimize_field": "安全事件总结、结束响应",
  "optimize_suggest": "给出具体的分析",
  "history": [
    {
      "role": "user",
      "content": "事件类型：网络安全事件，事件子类：数据勒索事件"
    },
    {
      "role": "assistant",
      "content": "{\"安全事件监测\": \"采用实时网络流量分析工具和入侵检测系统(IDS)进行监测，结合安全信息和事件管理(SIEM)系统集中收集和分析日志数据，确保及时发现异常数据访问和加密行为。\", \"安全事件分析、定级、上报\": \"分析流程包括确认事件性质、影响范围和攻击手法；定级依据《通信网络安全事件分级分类指南》，分为特别重大、重大、较大和一般四个等级；\", \"应急响应处置\": \"立即隔离受影响系统，防止勒索软件扩散；启动备份恢复流程，确保业务连续性；通知网络安全团队进行技术处置。\", \"安全事件取证和溯源\": \"使用数字取证工具收集和分析受感染系统的日志、内存转储和文件样本；通过IP追踪、恶意代码分析和网络行为分析技术溯源攻击者；确保取证过程符合法律要求，保护证据完整性。\", \"安全事件总结、结束响应\": \"编写详细的事件总结报告，包括事件原因、处置过程、损失评估和改进措施；组织内部评审会议，分享经验教训；更新应急预案和防护措施，防止类似事件再次发生；正式结束响应活动，恢复常态运营。\"}"
    },
    {
      "role": "user",
      "content": "优化'安全事件总结、结束响应',优化建议：给出具体的分析"
    }
  ]
}</pre>
                </div>
                
                <div class="example-data">
                    <h4>预案保存示例数据</h4>
                    <pre id="savePlanExampleData">{
  "event_type": "网络安全事件",
  "event_subtype": "数据勒索事件",
  "plan": {
    "安全事件监测": "采用实时网络流量分析工具和入侵检测系统(IDS)进行监测。",
    "安全事件分析、定级、上报": "分析流程包括确认事件性质、影响范围和攻击手法；定级依据《通信网络安全事件分级分类指南》。",
    "应急响应处置": "立即隔离受影响系统，防止勒索软件扩散；启动备份恢复流程，确保业务连续性。",
    "安全事件取证和溯源": "使用数字取证工具收集和分析受感染系统的日志、内存转储和文件样本。",
    "安全事件总结、结束响应": "编写详细的事件总结报告，包括事件原因、处置过程、损失评估和改进措施。"
  }
}</pre>
                </div>
                
                <div class="form-group">
                    <label for="emergencyPlanUrl">应急预案生成API地址:</label>
                    <input type="text" id="emergencyPlanUrl" value="http://1.94.252.115:8085/api/v1/generate_plan" readonly>
                </div>
                
                <div class="form-group">
                    <label for="savePlanUrl">预案保存API地址:</label>
                    <input type="text" id="savePlanUrl" value="http://1.94.252.115:8085/api/v1/save_plan" readonly>
                </div>
                
                <div class="form-group">
                    <label for="emergencyPlanData">预案生成请求数据 (JSON):</label>
                    <textarea id="emergencyPlanData" class="json-input" placeholder="请输入JSON格式的预案生成请求数据..."></textarea>
                </div>
                
                <div class="form-group">
                    <label for="optimizeData">预案优化请求数据 (JSON):</label>
                    <textarea id="optimizeData" class="json-input" placeholder="请输入JSON格式的预案优化请求数据..."></textarea>
                </div>
                
                <div class="form-group">
                    <label for="savePlanData">预案保存请求数据 (JSON):</label>
                    <textarea id="savePlanData" class="json-input" placeholder="请输入JSON格式的预案保存请求数据..."></textarea>
                </div>
                
                <button class="btn btn-success" onclick="loadDrillExampleData()">加载预案生成示例数据</button>
                <button class="btn btn-success" onclick="loadOptimizeExampleData()">加载预案优化示例数据</button>
                <button class="btn btn-success" onclick="loadSavePlanExampleData()">加载预案保存示例数据</button>
                <button class="btn" onclick="testEmergencyPlanGeneration()">测试预案生成</button>
                <button class="btn" onclick="testEmergencyPlanOptimize()">测试预案优化</button>
                <button class="btn" onclick="testSavePlan()">测试预案保存</button>
                <button class="btn btn-secondary" onclick="clearResponse('drillResponse')">清空响应</button>
                
                <div id="drillResponse" class="response info">等待测试...</div>
            </div>
            
            <!-- 全流程测试 -->
            <div id="workflow" class="tab-content">
                <h3>全流程测试</h3>
                <p>测试预案生成 → 脚本生成 → 脚本保存 → 知识库查询的完整流程</p>
                
                <div class="form-group">
                    <label for="workflowUrl">服务器地址:</label>
                    <input type="text" id="workflowUrl" value="http://1.94.252.115:8085" readonly>
                </div>
                
                <button class="btn btn-success" onclick="testFullWorkflow()">开始全流程测试</button>
                <button class="btn btn-secondary" onclick="clearResponse('workflowResponse')">清空响应</button>
                
                <div id="workflowResponse" class="response info">等待测试...</div>
            </div>
            
            <!-- 错误测试 -->
            <div id="error" class="tab-content">
                <h3>错误情况测试</h3>
                <p>测试各种错误情况的处理</p>
                
                <div class="form-group">
                    <label for="errorUrl">API地址:</label>
                    <input type="text" id="errorUrl" value="http://1.94.252.115:8085/api/v1/save_script" readonly>
                </div>
                
                <button class="btn btn-danger" onclick="testErrorCases()">测试错误情况</button>
                <button class="btn btn-secondary" onclick="clearResponse('errorResponse')">清空响应</button>
                
                <div id="errorResponse" class="response info">等待测试...</div>
            </div>
        </div>
    </div>

    <script>
        // 显示指定标签页
        function showTab(tabName) {
            // 隐藏所有标签页内容
            const tabContents = document.querySelectorAll('.tab-content');
            tabContents.forEach(content => content.classList.remove('active'));
            
            // 移除所有标签的active类
            const tabs = document.querySelectorAll('.tab');
            tabs.forEach(tab => tab.classList.remove('active'));
            
            // 显示指定标签页
            document.getElementById(tabName).classList.add('active');
            event.target.classList.add('active');
        }
        
        // 加载示例数据
        function loadExampleData() {
            const exampleData = document.getElementById('exampleData').textContent;
            document.getElementById('saveData').value = exampleData;
        }
        
        // 加载应急预案示例数据
        function loadDrillExampleData() {
            const drillExampleData = document.getElementById('drillExampleData').textContent;
            document.getElementById('emergencyPlanData').value = drillExampleData;
        }
        
        // 加载预案优化示例数据
        function loadOptimizeExampleData() {
            const optimizeExampleData = document.getElementById('optimizeExampleData').textContent;
            document.getElementById('optimizeData').value = optimizeExampleData;
        }
        
        // 加载预案保存示例数据
        function loadSavePlanExampleData() {
            const savePlanExampleData = document.getElementById('savePlanExampleData').textContent;
            document.getElementById('savePlanData').value = savePlanExampleData;
        }
        
        // 加载脚本生成示例数据
        function loadScriptGenerateExampleData() {
            const scriptGenerateExampleData = document.getElementById('scriptGenerateExampleData').textContent;
            document.getElementById('scriptGenerateData').value = scriptGenerateExampleData;
        }
        

        
        // 清空响应
        function clearResponse(elementId) {
            const element = document.getElementById(elementId);
            element.textContent = '等待测试...';
            element.className = 'response info';
        }
        
        // 更新响应显示
        function updateResponse(elementId, content, type = 'info') {
            const element = document.getElementById(elementId);
            element.textContent = content;
            element.className = `response ${type}`;
        }
        
        // 测试脚本保存
        async function testScriptSave() {
            const url = document.getElementById('saveUrl').value;
            const dataText = document.getElementById('saveData').value;
            
            updateResponse('saveResponse', '正在测试演练脚本保存...', 'info');
            
            try {
                const data = JSON.parse(dataText);
                
                const startTime = Date.now();
                const response = await fetch(url, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });
                const endTime = Date.now();
                
                const result = await response.json();
                const duration = endTime - startTime;
                
                let responseText = `HTTP状态码: ${response.status}\n`;
                responseText += `响应时间: ${duration}ms\n\n`;
                responseText += `响应结果:\n${JSON.stringify(result, null, 2)}`;
                
                if (response.status === 200 && result.status_code === 0) {
                    updateResponse('saveResponse', responseText, 'success');
                } else {
                    updateResponse('saveResponse', responseText, 'error');
                }
                
            } catch (error) {
                updateResponse('saveResponse', `请求失败: ${error.message}`, 'error');
            }
        }
        
        // 测试应急预案生成
        async function testEmergencyPlanGeneration() {
            const url = document.getElementById('emergencyPlanUrl').value;
            const dataText = document.getElementById('emergencyPlanData').value;
            
            updateResponse('drillResponse', '正在测试应急预案生成...', 'info');
            
            try {
                const data = JSON.parse(dataText);
                
                const startTime = Date.now();
                const response = await fetch(url, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });
                const endTime = Date.now();
                
                const result = await response.json();
                const duration = endTime - startTime;
                
                let responseText = `HTTP状态码: ${response.status}\n`;
                responseText += `响应时间: ${duration}ms\n\n`;
                responseText += `响应结果:\n${JSON.stringify(result, null, 2)}`;
                
                if (response.status === 200 && result.status_code === 0) {
                    updateResponse('drillResponse', responseText, 'success');
                } else {
                    updateResponse('drillResponse', responseText, 'error');
                }
                
            } catch (error) {
                updateResponse('drillResponse', `请求失败: ${error.message}`, 'error');
            }
        }
        
        // 测试预案优化
        async function testEmergencyPlanOptimize() {
            const url = document.getElementById('emergencyPlanUrl').value;
            const dataText = document.getElementById('optimizeData').value;
            
            updateResponse('drillResponse', '正在测试预案优化...', 'info');
            
            try {
                const data = JSON.parse(dataText);
                
                const startTime = Date.now();
                const response = await fetch(url, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });
                const endTime = Date.now();
                
                const result = await response.json();
                const duration = endTime - startTime;
                
                let responseText = `HTTP状态码: ${response.status}\n`;
                responseText += `响应时间: ${duration}ms\n\n`;
                responseText += `响应结果:\n${JSON.stringify(result, null, 2)}`;
                
                if (response.status === 200 && result.status_code === 0) {
                    updateResponse('drillResponse', responseText, 'success');
                } else {
                    updateResponse('drillResponse', responseText, 'error');
                }
                
            } catch (error) {
                updateResponse('drillResponse', `请求失败: ${error.message}`, 'error');
            }
        }
        
        // 测试预案保存
        async function testSavePlan() {
            const url = document.getElementById('savePlanUrl').value;
            const dataText = document.getElementById('savePlanData').value;
            
            updateResponse('drillResponse', '正在测试预案保存...', 'info');
            
            try {
                const data = JSON.parse(dataText);
                
                const startTime = Date.now();
                const response = await fetch(url, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });
                const endTime = Date.now();
                
                const result = await response.json();
                const duration = endTime - startTime;
                
                let responseText = `HTTP状态码: ${response.status}\n`;
                responseText += `响应时间: ${duration}ms\n\n`;
                responseText += `响应结果:\n${JSON.stringify(result, null, 2)}`;
                
                if (response.status === 200 && result.status_code === 0) {
                    updateResponse('drillResponse', responseText, 'success');
                } else {
                    updateResponse('drillResponse', responseText, 'error');
                }
                
            } catch (error) {
                updateResponse('drillResponse', `请求失败: ${error.message}`, 'error');
            }
        }
        
        // 测试脚本生成
        async function testScriptGenerate() {
            const url = document.getElementById('scriptGenerateUrl').value;
            const dataText = document.getElementById('scriptGenerateData').value;
            
            updateResponse('saveResponse', '正在测试演练脚本生成...', 'info');
            
            try {
                const data = JSON.parse(dataText);
                
                const startTime = Date.now();
                const response = await fetch(url, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });
                const endTime = Date.now();
                
                const result = await response.json();
                const duration = endTime - startTime;
                
                let responseText = `HTTP状态码: ${response.status}\n`;
                responseText += `响应时间: ${duration}ms\n\n`;
                responseText += `响应结果:\n${JSON.stringify(result, null, 2)}`;
                
                if (response.status === 200 && result.status_code === 0) {
                    updateResponse('saveResponse', responseText, 'success');
                } else {
                    updateResponse('saveResponse', responseText, 'error');
                }
                
            } catch (error) {
                updateResponse('saveResponse', `请求失败: ${error.message}`, 'error');
            }
        }
        

        
        // 测试全流程
        async function testFullWorkflow() {
            const baseUrl = document.getElementById('workflowUrl').value;
            let responseText = '开始全流程测试...\n\n';
            
            try {
                // 1. 测试应急预案生成
                responseText += '步骤1: 测试应急预案生成...\n';
                const planData = {
                    event_type: "网络安全事件",
                    event_subtype: "数据勒索事件",
                    optimize_field: "",
                    optimize_suggest: "",
                    history: []
                };
                
                const planResponse = await fetch(`${baseUrl}/api/v1/generate_plan`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(planData)
                });
                
                const planResult = await planResponse.json();
                if (planResponse.status === 200 && planResult.status_code === 0) {
                    responseText += '✅ 应急预案生成成功\n';
                    
                    // 转换为字典格式
                    const planDict = {};
                    planResult.plan.forEach(item => {
                        planDict[item.field_name] = item.content;
                    });
                    
                    // 2. 测试脚本生成
                    responseText += '\n步骤2: 测试脚本生成...\n';
                    const scriptData = {
                        equipment: "网络防火墙",
                        sceneDesc: "模拟网络攻击场景",
                        plan: planDict,
                        scriptNode: [
                            {
                                nodeOrder: 1,
                                nodeName: "演练启动",
                                nodeType: "流程节点",
                                children: [
                                    {
                                        id: "test-id-1",
                                        nodeName: "对话节点",
                                        nodeType: "对话节点",
                                        nodeContent: "",
                                        participants: {
                                            id: "1",
                                            name: "安全管理员",
                                            groupId: "group-1",
                                            groupName: "演练主持人"
                                        }
                                    }
                                ]
                            }
                        ]
                    };
                    
                    const scriptResponse = await fetch(`${baseUrl}/api/v1/generate_drill_script`, {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        body: JSON.stringify(scriptData)
                    });
                    
                    const scriptResult = await scriptResponse.json();
                    if (scriptResponse.status === 200 && scriptResult.status_code === 0) {
                        responseText += '✅ 脚本生成成功\n';
                        
                        // 3. 测试脚本保存
                        responseText += '\n步骤3: 测试脚本保存...\n';
                        const saveData = {
                            equipment: scriptData.equipment,
                            sceneDesc: scriptData.sceneDesc,
                            plan: planDict,
                            scriptNode: scriptResult.scriptNode
                        };
                        
                        const saveResponse = await fetch(`${baseUrl}/api/v1/save_script`, {
                            method: 'POST',
                            headers: { 'Content-Type': 'application/json' },
                            body: JSON.stringify(saveData)
                        });
                        
                        const saveResult = await saveResponse.json();
                        if (saveResponse.status === 200 && saveResult.status_code === 0) {
                            responseText += '✅ 脚本保存成功\n';
                            
                            // 4. 测试知识库查询
                            responseText += '\n步骤4: 测试知识库查询...\n';
                            const kbResponse = await fetch(`${baseUrl}/knowledge_base/documents`);
                            const kbResult = await kbResponse.json();
                            
                            if (kbResponse.status === 200 && kbResult.code === 0) {
                                responseText += `✅ 知识库查询成功，文档总数: ${kbResult.data.length}\n`;
                                responseText += '\n🎉 全流程测试完成！所有步骤都成功执行！';
                            } else {
                                responseText += '❌ 知识库查询失败\n';
                            }
                        } else {
                            responseText += '❌ 脚本保存失败\n';
                        }
                    } else {
                        responseText += '❌ 脚本生成失败\n';
                    }
                } else {
                    responseText += '❌ 应急预案生成失败\n';
                }
                
            } catch (error) {
                responseText += `❌ 测试过程中发生错误: ${error.message}`;
            }
            
            updateResponse('workflowResponse', responseText, 'info');
        }
        
        // 测试错误情况
        async function testErrorCases() {
            const url = document.getElementById('errorUrl').value;
            let responseText = '开始测试错误情况...\n\n';
            
            const errorTests = [
                {
                    name: '缺少equipment参数',
                    data: {
                        sceneDesc: '测试场景',
                        plan: { '测试': '内容' },
                        scriptNode: []
                    }
                },
                {
                    name: '缺少sceneDesc参数',
                    data: {
                        equipment: '测试设备',
                        plan: { '测试': '内容' },
                        scriptNode: []
                    }
                },
                {
                    name: 'plan不是字典格式',
                    data: {
                        equipment: '测试设备',
                        sceneDesc: '测试场景',
                        plan: '不是字典',
                        scriptNode: []
                    }
                },
                {
                    name: 'scriptNode不是数组格式',
                    data: {
                        equipment: '测试设备',
                        sceneDesc: '测试场景',
                        plan: { '测试': '内容' },
                        scriptNode: '不是数组'
                    }
                }
            ];
            
            for (const test of errorTests) {
                responseText += `测试: ${test.name}\n`;
                
                try {
                    const response = await fetch(url, {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        body: JSON.stringify(test.data)
                    });
                    
                    const result = await response.json();
                    
                    if (response.status === 200 && result.status_code === 10001) {
                        responseText += `✅ 通过 - 正确返回参数错误\n`;
                    } else {
                        responseText += `❌ 失败 - 状态码: ${result.status_code}\n`;
                    }
                } catch (error) {
                    responseText += `❌ 异常: ${error.message}\n`;
                }
                
                responseText += '\n';
            }
            
            responseText += '错误情况测试完成！';
            updateResponse('errorResponse', responseText, 'info');
        }
        
        // 页面加载时加载示例数据
        window.onload = function() {
            loadExampleData();
            loadDrillExampleData();
            loadOptimizeExampleData();
            loadSavePlanExampleData();
            loadScriptGenerateExampleData();
        };
    </script>
</body>
</html> 